﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db;
using HengTong.Model;
using HengTong.Model.Db.Hr;


namespace HengTong.ViewModel.Person.SysPersonEducationVms
{
    public partial class SysPersonEducationListVm : BasePagedListVM<SysPersonEducationView, SysPersonEducationSearcher>
    {

        protected override IEnumerable<IGridColumn<SysPersonEducationView>> InitGridHeader()
        {
            return new List<GridColumn<SysPersonEducationView>>{
                this.MakeGridHeader(x => x.PersonName),
                this.MakeGridHeader(x => x.School),
                this.MakeGridHeader(x => x.Major),
                this.MakeGridHeader(x => x.EducationLevel),
                this.MakeGridHeader(x => x.EducationSystem),
                this.MakeGridHeader(x => x.EnrollmentDate),
                this.MakeGridHeader(x => x.GraduationDate),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysPersonEducationView> GetSearchQuery()
        {
            var query = DC.Set<SysPersonEducation>()
                .CheckEqual(Searcher.PersonId, x=>x.PersonId)
                .CheckContain(Searcher.School, x=>x.School)
                .CheckEqual(Searcher.EducationLevel, x=>x.EducationLevel)
                .Select(x => new SysPersonEducationView
                {
				    ID = x.ID,
                    PersonName = x.Person.Name,
                    School = x.School,
                    Major = x.Major,
                    EducationLevel = x.EducationLevel,
                    EducationSystem = x.EducationSystem,
                    EnrollmentDate = x.EnrollmentDate,
                    GraduationDate = x.GraduationDate,
                    Attachments = x.Attachments
                })
                .OrderBy(x => x.EnrollmentDate ?? DateTime.MaxValue);
            return query;
        }

    }

    public class SysPersonEducationView : SysPersonEducation{
        [Display(Name = "姓名")]
        public String PersonName { get; set; }

    }
}
